nums = [1, 7, 4, 9, 2, 5]

var wiggleMaxLength = function (nums) {
    let left = 0
    let right = 0
    let result = 1
    let len = nums.length
    for (let i = 0; i < len - 1; i++) {
        right = nums[i + 1] - nums[i]
        if ((left >= 0 && right < 0) || (left <= 0 && right > 0)) {
            result++
            left = right
        }
    }
    return result
};

console.log(wiggleMaxLength(nums));
